home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12604 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: RAND_MAX
  5. Date: 1 Apr 96 17:32:45 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.828379965@rscernix>
  8. References: <4jnr55$e6l@skivs.ski.org>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4jnr55$e6l@skivs.ski.org> gt@ns.oon.or.jp (Gemini Thunder) writes:
  13.  
  14. >K&R2 says:
  15. >  "rand returns a a pseudo-random integer in the range 0 to RAND_MAX,
  16. >which is at least 32767"
  17. >
  18. >It looks like RAND_MAX is not required to be the same as any other
  19. >limit (such as MAX_INT, etc.), that is fine, but why?  
  20.  
  21. To allow the implementor more freedom in choosing the rand() algorithm.
  22.  
  23. >Wouldn't it be easier if RAND_MAX == MAX_INT or some other value?  
  24.                                       ^^^^^^^
  25.                             You meant INT_MAX, right?
  26.  
  27. Huh???  Why would it be easier to write INT_MAX instead of RAND_MAX?
  28. One letter less to type? :-)
  29.  
  30. >The reason I say this is how can you be sure your array will hold a
  31. >RAND_MAX sized integer, without some checking before hand, if RAND_MAX
  32. >is out there doing its own thing?
  33.  
  34. I'm afraid I don't understand what you mean.  Anyway, rand() returns
  35. an int, so it is guaranteed that RAND_MAX <= INT_MAX.
  36.  
  37. Dan
  38. --
  39. Dan Pop
  40. CERN, CN Division
  41. Email: danpop@mail.cern.ch 
  42. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  43.